using System;
using System.Collections.Generic;
using System.Text;
using MacomberMap.Common.User_Interfaces.Components;
using System.Xml;
using MacomberMap.Common.Components;
using MacomberMap.Common.Database_Interface;
using System.Drawing;
using System.Windows.Forms;

namespace MacomberMap.Common.User_Interfaces.One_Lines.Elements
{
    /// <summary>
    /// This class holds information on a static var compensator
    /// </summary>
    public class MM_OneLine_StaticVarCompensator: MM_OneLine_Element
    {
        #region Initialization

        /// <summary>
        /// Initialize a new static var compensator
        /// </summary>
        /// <param name="DisplayParams"></param>
        public MM_OneLine_StaticVarCompensator(MM_OneLine_Display DisplayParams)
            : base(DisplayParams)
        {
        }

        /// <summary>
        /// Initialize a new static var compensator
        /// </summary>
        /// <param name="BaseElement"></param>
        /// <param name="DisplayParams"></param>
        /// <param name="Orientation"></param>
        public MM_OneLine_StaticVarCompensator(MM_Element BaseElement, MM_OneLine_Display DisplayParams, MM_OneLine_Element.enumOrientations Orientation)
            : base(BaseElement, DisplayParams, Orientation)
        {
        }

        /// <summary>
        /// Initialize a new static var compensator
        /// </summary>
        /// <param name="BaseElement"></param>
        /// <param name="DisplayParams"></param>
        /// <param name="DbConnection">The database connection</param>
        public MM_OneLine_StaticVarCompensator(XmlElement BaseElement, MM_OneLine_Display DisplayParams, MM_Database DbConnection)
            : base(BaseElement, DisplayParams, DbConnection)
        {            
        }

        
        #endregion

        #region Rendering
        /// <summary>
        /// Draw the static var compensator
        /// </summary>
        /// <param name="g"></param>
        public override void DrawImage(Graphics g)
        {
            using (Pen DrawPen = new Pen(KVLevel == null ? Color.Red : KVLevel.Energized.ForeColor))
            {
                //g.FillRectangle(Brushes.Black, this.DisplayRectangle);
                if (Orientation == enumOrientations.Up || Orientation == enumOrientations.Vertical)
                {

                    g.DrawLines(DrawPen, IntToPoints(18, 0, 18, 1, 16, 2, 14, 3, 12, 4, 9, 6, 8, 7, 7, 8, 6, 10, 6, 12, 7, 13, 8, 14, 10, 15, 13, 16, 16, 17, 19, 17, 22, 17, 26, 16, 28, 15, 30, 14, 31, 12, 31, 10, 30, 8, 29, 7, 28, 6, 26, 5, 23, 4, 20, 4, 17, 5, 15, 6, 13, 7, 10, 9, 8, 11, 7, 12, 6, 14, 6, 16, 8, 18, 12, 20, 16, 21, 17, 21, 20, 21, 24, 20, 27, 19, 30, 17, 31, 15, 31, 13, 30, 11, 28, 10, 26, 9, 23, 8, 21, 8, 19, 8, 17, 9, 15, 10, 13, 11, 10, 13, 8, 15, 7, 16, 6, 17, 6, 19, 7, 20, 8, 21, 9, 22, 11, 23, 13, 24, 16, 25, 18, 25, 18, 26, 18, 35));
                    g.DrawLine(DrawPen, 63, 2, 63, 8);
                    g.DrawLine(DrawPen, 55, 8, 71, 8);
                    g.DrawLine(DrawPen, 63, 10, 63, 35);
                    g.DrawArc(DrawPen, 55, 8, 16, 16, 180, 180);
                    g.DrawLine(DrawPen, 18, 35, 63, 35);

                }
                else if (Orientation == enumOrientations.Down)
                {
                    g.DrawLines(DrawPen, IntToPoints(62,36,62,42,60,43,58,44,56,45,53,47,52,48,51,49,50,51,50,53,51,54,52,55,54,56,57,57,60,58,63,58,66,58,70,57,72,56,74,55,75,53,75,51,74,49,73,48,72,47,70,46,67,45,64,45,61,46,59,47,57,48,54,50,52,52,51,53,50,55,50,57,52,59,56,61,60,62,61,62,64,62,68,61,71,60,74,58,75,56,75,54,74,52,72,51,70,50,67,49,65,49,63,49,61,50,59,51,57,52,54,54,52,56,51,57,50,58,50,60,51,61,52,62,53,63,55,64,57,65,60,66,62,66,62,67,62,69));
                    g.DrawLine(DrawPen, 21, 36, 21, 48);
                    g.DrawLine(DrawPen, 13, 48, 29, 48);
                    g.DrawLine(DrawPen, 21, 50, 21, 66);
                    g.DrawArc(DrawPen, 13, 50, 16, 16, 180, 180);                                                          
                    g.DrawLine(DrawPen, 21, 36, 62, 36);
                    
                }
                else if (Orientation == enumOrientations.Left || Orientation == enumOrientations.Horizontal || Orientation == enumOrientations.Unknown)
                {                    
                    g.DrawLines(DrawPen, IntToPoints(35, 27, 40, 27, 41, 28, 42, 30, 43, 33, 44, 35, 45, 37, 46, 38, 47, 39, 49, 39, 51, 38, 53, 36, 54, 34, 55, 31, 56, 27, 56, 22, 55, 19, 54, 17, 51, 15, 49, 15, 47, 16, 45, 18, 44, 21, 44, 26, 46, 32, 47, 34, 49, 37, 50, 38, 52, 39, 54, 39, 52, 32, 57, 38, 58, 37, 60, 34, 61, 31, 62, 27, 62, 22, 61, 19, 60, 17, 57, 15, 55, 15, 53, 16, 52, 17, 51, 18, 50, 20, 49, 23, 49, 27, 50, 30, 52, 34, 54, 37, 57, 39, 59, 39, 61, 38, 62, 37, 64, 34, 65, 31, 66, 28, 67, 27, 69, 27, 71, 27));
                    g.DrawLine(DrawPen, 62, 53, 56, 53);
                    g.DrawLine(DrawPen, 56, 45, 56, 61);
                    g.DrawLine(DrawPen, 54, 53, 35, 53);
                    g.DrawArc(DrawPen, 38, 45, 16, 16, 270, 180);
                    g.DrawLine(DrawPen, 35, 27, 35, 53);
                }
                else if (Orientation == enumOrientations.Right)
                {
                    

                    //Draw the reactor
                    g.DrawLines(DrawPen, IntToPoints(1, 18, 2, 18, 3, 19, 4, 21, 5, 24, 6, 26, 7, 28, 8, 29, 9, 30, 11, 30, 13, 29, 15, 27, 16, 25, 17, 22, 18, 18, 18, 13, 17, 10, 16, 8, 13, 6, 11, 6, 9, 7, 7, 9, 6, 12, 6, 17, 8, 23, 9, 25, 11, 28, 12, 29, 14, 30, 16, 30, 17, 30, 19, 29, 20, 28, 22, 25, 23, 22, 24, 18, 24, 13, 23, 10, 22, 8, 19, 6, 17, 6, 15, 7, 14, 8, 13, 9, 12, 11, 11, 14, 11, 18, 12, 21, 14, 25, 16, 28, 19, 30, 21, 30, 23, 29, 24, 28, 26, 25, 27, 22, 28, 19, 29, 18, 31, 18, 33, 18));

                    //Draw the capacitor
                    g.DrawLine(DrawPen, 13, 58, 7, 58);
                    g.DrawLine(DrawPen, 13, 50, 13, 66);
                    g.DrawLine(DrawPen, 33, 58, 15, 58);
                    g.DrawArc(DrawPen, 15, 50, 16, 16, 90, 180);

                    //Draw the line connecting reactor and capacitor
                    g.DrawLine(DrawPen, 34, 18, 34, 58);
                }

                //Draw the arrow
                //g.DrawLine(DrawPen, 9, 63, 64, 8);
               // g.FillPolygon(DrawPen.Brush, IntToPoints(56, 4, 68, 13, 68, 0, 56, 4));
            }
        }
        #endregion
    }
}
